package models.common.entity;


import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Transient;

import common.constants.ConfConst;
import common.constants.Constants;
import common.utils.DateUtil;
import common.utils.Security;
import play.db.jpa.Model;

/**
 * 商票信息表
 *@author xiaojun
 *@version 2017-4-14 下午2:12:52
 */
@Entity
public class t_commercial_paper_info extends Model{
	/**
	 * 构造器
	 */
	public t_commercial_paper_info(){};
	public t_commercial_paper_info(double paper_money, String paper_pic_on,String paper_pic_under,String bill_code,String drawee,String account_num,String account_bank){
		this.paper_money=paper_money;
		this.paper_pic_on=paper_pic_on;
		this.paper_pic_under=paper_pic_under;
		this.bill_code=bill_code;
		this.drawee=drawee;
		this.account_num=account_num;
		this.account_bank=account_bank;
	};

	  /**id */
	@Transient
	public String sign;
	public String getSign () {
		
		return Security.addSign(this.id, Constants.BID_ID_SIGN, ConfConst.ENCRYPTION_KEY_DES);
	}
	/**登记时间*/
	public Date time ;
	  /**商票图片（正） */
    public String paper_pic_on;

    /**商票图片(反) */
    public String paper_pic_under;

    /**商票金额 */
    public double paper_money;
    /**融通比例*/
    public double finacing_ratio;
    /**可用额度*/
    public double  finacing_residue_limit;
    /**融通已使用金额*/
    public double  finacing_used_limit;
    
    /**商票到期日期 */
    public Date paper_expire_time;

    /**凭证号码 */
    public String bill_code;

    /**开户账号 */
    public String account_num;

    /**开户银行 */
    public String account_bank;
    /** 开户银行行号*/
    public String bank_no;
    /**商票出票时间 */
    public Date paper_create_time;

    /**付款人（出票人） */
    public String drawee;

    /**出票人id */
    public long receive_id;

    /**是否数字商票  0 不是  1 是 */
    public int is_digital;

    /**是否转让  0 可转 1 不可转 */
    public int allow_transfer;

    /**债权债务id */
    public long debt_creditor_id;
    /**流转id（数字商票id或背书id） */
    public long circulation_id;
    /**是否背书 0 不是  1 是 */
    public int is_endorse;
    @Transient
	public String creditorSign;
	public String getCreditorSign () {
		
		return Security.addSign(this.debt_creditor_id, Constants.BID_ID_SIGN, ConfConst.ENCRYPTION_KEY_DES);
	}
    /**原始票id */
    public long orginal_paper_id;

    /**凭证号码 */
    public String certificate_code;
    /**商票状态 0 已登记 1 已质押 2 已到期 3 已结清 4 已撤销*/
    public int paper_status;
    
    /**收款人 */
    public String receive_name;
    /**收款人账户 */
    public String receive_num;
    /**收款人 银行*/
    public String receive_bank;
    /**还款状态  0 未还款  1 已还款*/
    public int repayment_status;
    
    /**托收状态 0 未托收  1 已托收 2 已拒付*/
    public int collection_status;
    /**当前兑现金额*/
    public double cash_amount;
    /**已兑现总金额*/
    public double cash_all_amount;
    
    /**兑现或拒付时间**/
    public Date cash_time;
    /**拒付理由**/
    public String  dishonour_excuse;
    /**付款或者拒付**/
    public int payment_or_dishonour;
	/**合同的编号 */
	public String pact_no;
	
	/**放款人id */
	public long lender_id;
	/**放款人名称 */
	public String lender_name;
	/**所属授信id */
	public long credit_limit_id;
	/**原始授信id */
	public long receive_credit_id;
	/**挂牌标识 */
	public int is_listing;
    public TicketStatus getStatus() {
    	TicketStatus status = TicketStatus.getEnum(this.paper_status);
		
		return status;
	}
    
    /**
   	 * 商票的状态
   	 *
   	 * @description 
   	 *
   	 * @author xiaojun
   	 * @createDate 2017年4月15日
   	 */
   	public enum TicketStatus {
   		
   		/** 待接收质押 */
   		REGISTER(0, "待接收质押"),
   		
   		/** 已接受质押 */
   		 PLEDGE(1, "已接受质押"),
   		/** 已到期 */
   		EXPIRE(2, "已到期"),
   		/**已结清*/
   		ALL_SQUARED(3,"已结清"),
   		 /**已撤销*/
   		REVOCATION(4, "已撤销"),
   		
   		/**已拒收*/
   		REJECTION(8, "已拒收"),
   		
   		/**已解除质押*/
   		INVALID(5, "已解除质押"),
   		
   		/**待签收*/
   		TBC(6, "待签收"),
   		/** 已签收*/
   		CONFIRM(7, "已签收"),
   		/** 已划款*/
   		REPAYMENT(9,"已划款"),
   		/** 合同待签署 */
   		NOT_SIGN(-1, "合同待签署"),
   		;
   		
   
   		
   		/** 状态 */
   		public int code;
   		
   		/** 描述 */
   		public String value;
   		
   		
   		
   		
   		private TicketStatus(int code, String value){
   			this.code = code;
   			this.value = value;
   		}
   		
   		public static TicketStatus getEnum(int code){
   			TicketStatus[] bidstatus = TicketStatus.values();
   			for(TicketStatus income:bidstatus){
   				if(income.code == code){
   					
   					return income;
   				}
   			}
   			
   			return null;
   		}
   	}
    
   
}